{extend name="public/base" /}
{block name="pjax_container"}
<?php
    $titleTypeName = '积分奖扣编辑(专审事件)';
?>
<style>


    .content-header>.breadcrumb>li {
        color: #999;
    }

    .content-header>.breadcrumb>.active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }


    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .nav-tabs-custom {
        margin-top: 16px;
    }

    .modal-content {
        margin-top: 150px;
        width: 600px;
        height: 692px;

    }

    .modal-body {
        padding: 27px;
        height: 570px;
        display: flex;
    }

    .modal-right {
        flex: 1;
        height: 523px;
        border: 1px solid #eee;
        margin-left: 30px;
    }

    .modal-right>h4 {
        width: 100%;
        display: flex;
        justify-content: space-around;
    }

    .form-control {
        border-radius: 6px;
    }

    .table-body {
        width: 546px;
        height: 470px;
        margin-top: 10px;
        border-radius: 6px;
        background-color: #eee;
    }

    .table-left {
        margin-right: 2%;
        width: 49%;
        height: 100%;
        float: left;
        border: 1px solid #eee;
        background-color: #fff;
    }
    .table-right {
        width: 49%;
        height: 100%;
        border: 1px solid #eee;
        float: left;
        background-color: #fff;
    }
    .layui-tree-entry {
        height: 100%;
        width: 100%;
        padding-right: 10px;
        line-height: 24px;

    }
    .table-right>p {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;
    }

    .table-right>h4 {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;

    }

    .table-right>p>span {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;
        width: 80%;
        display: inline-block;
        letter-spacing: 1px;

    }


    .tab-content {
        border-bottom: 0px solid #f3f3f3;
    }

    .box-footer {
        display: none;
        border-top: 0px solid #f4f4f4;
    }

    .submits {
        padding: 8px 20px;
        border: none;
        outline: none;
    }
    /* 快捷设置样式 */
    .fast_set{
        margin-top: 20px;
    }
    .fast_set_title{
        font-size: 14px;
        line-height: 34px;
        text-align: center;
    }
    .tab-pane .things-tips-parent{
        position:relative;
    }
    .tab-pane .things-tips{
        display: none!important;
        position: absolute;
        right: 0px;
        top: 0px;
        display: inline-block;
    }
    .tab-pane .things-tips-parent:hover .things-tips{
        display: block!important;
    }
    .tab-pane .things-tips .content_tips{
        display: none;
        position: absolute;
        top: 0;
        width: 350px;
        line-height: 18px;
        background: #fff;
        padding: 8px;
        border: 1px solid #dadada;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        color: rgba(0, 0, 0, 0.65);
        border-radius: 4px;
    }
</style>
<section class="content-header">
    <ol class="breadcrumb">
        <li>积分管理</li>
        <li>我提交的奖扣</li>
        <li class="active">{$titleTypeName}</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST"
                  action="/{$Think.MODULE_NAME}/{$Think.CONTROLLER_NAME}/{$Think.ACTION_NAME}" onsubmit="return false">
                <input type="hidden" name="id" value="{$list.theme.id|default=0}" />
                <input name="check_opinion" class="check_opinion" value="" type="hidden">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm"
                                                  style="padding:10px 2px;"><i class="fa fa-list"></i> 返回</a></li>
                    </ul>
                    <div class="tab-content-wrap">
                        <div class="tab-content">
                            {php}$tmp_index = 0;{/php}
                            {foreach name="$list['event']" item="vo" key="ko"}
                            <div class="tab-pane active">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">事件编号:</label>
                                    <div class="col-sm-4 thing_num" style="line-height:33px;">
                                        {$tmp_index+1}
                                    </div>
                                    <input type="hidden" class="even_number" name="number[{$tmp_index}]" value="{$tmp_index}">
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">事件</label>
                                    <div class="col-sm-4 things-tips-parent">
                                        <input type="text" name="" value="{$vo.name}" is_piece="{$vo.is_piece}" style="border-radius: 6px;" class="form-control things_check" placeholder="事件选择" />
                                        <input type="hidden" class="things_check_id" name="event_id[]" integral_a_start="{$vo.integral_a_start??0}" integral_a_end="{$vo.integral_a_end??0}" integral_b_start="{$vo.integral_b_start??0}" integral_b_end="{$vo.integral_b_end??0}" value="{$vo.id??''}" >
                                        <div class="things-tips">
                                            {if condition="1"}
                                                <div class="content_tips" style="left: 0px; top: 0px; display: block;"> 
                                                    <p>事件分类：<span>{$vo.p_cate_name}/{$vo.cate_name}</span></p>
                                                    <p>分值范围：<span>A分:{$vo.integral_a_start} ~ {$vo.integral_a_end} B分:{$vo.integral_b_start} ~ {$vo.integral_b_end}</span></p>
                                                    <p>事件属性：{if condition="$vo.is_piece eq 1"}计件事件{/if}{if condition="isset($vo.is_check) && $vo.is_check eq 1"}专审事件{/if}</p>
                                                    <p>备注信息：</p>
                                                    <p><span>{$vo.event_desc}</span></p>
                                                </div>
                                            {/if}
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">描述</label>
                                    <div class="col-sm-4">
                                        <textarea name="event_desc[]" class="form-control" style="height: 100px;border-radius: 6px;">{$vo.event_desc}</textarea>
                                    </div>
                                </div>
                                <div style="text-align: right;width: 50%">
                                    <div class="btn-group add_user" style="margin-left: 20px;">
                                        <div type="submit" class="btn btn-info pull-right add_take">添加参与人</div>
                                    </div>
                                    <div class="btn-group">
                                        <button class="btn btn-info cancel_this">删除</button>
                                    </div>
                                </div>
                                <div class="fast_set">
                                    <div class="form-group user_item">
                                        <label class="col-sm-2 control-label" ></label>
                                        <div class="col-sm-1">
                                            <div class="fast_set_title">快捷设置</div> 
                                        </div>
                                        <label class="col-sm-1 control-label">A分</label>
                                        <div class="col-sm-1">
                                            <input class="form-control" data-name="integral_a" type="number" name="" value="">
                                        </div>
                                        <label class="col-sm-1 control-label">B分</label>
                                        <div class="col-sm-1">
                                            <input class="form-control" data-name="integral_b" type="number" name="" value="">
                                        </div>
                                        {if condition="$vo['is_piece']"}
                                            <div class="fast_set_isPiece">
                                                <label class="col-sm-1 control-label">计件</label>
                                                <div class="col-sm-1">
                                                    <input class="form-control" data-name="piece_rate" type="number" min="1" value="1" name=""> 
                                                </div>
                                            </div>
                                        {/if}
                                    </div>
                                </div> 
                                <div class="user_list" style="margin-top: 10px;">
                                    {foreach name="$vo['list']" item="vo2" key="ko2"}
                                     <div class="form-group user_item">
                                        <label class="col-sm-2 control-label">参与人</label>
                                        <div class="col-sm-1">
                                            <input type="text" name="" disabled style="border-radius: 6px;" value="{$vo2.user_name}" class="form-control cyr_name">
                                            <input type="hidden" class="cyr_id" name="user_id[{$tmp_index}][]" user_name="{$vo2.user_name}" value="{$vo2.user_id}" input_user_num="{$vo2.job_number}" apart_name="{$vo2.d_name}" limits_b="0">
                                        </div>
                                        <label class="col-sm-1 control-label">A分</label>
                                        <div class="col-sm-1">
                                            <input class="form-control integral_a" type="number" name="integral_a[{$tmp_index}][]" value="{$vo2.integral_a}">
                                        </div>
                                        <label class="col-sm-1 control-label">B分</label>
                                        <div class="col-sm-1">
                                            <input class="form-control integral_b" type="number" name="integral_b[{$tmp_index}][]" value="{$vo2.integral_b}">
                                        </div>
                                         {if condition="$vo['is_piece']"}
                                        <label class="col-sm-1 control-label">计件</label>
                                        <div class="col-sm-1">
                                            <input class="form-control piece_rate" type="number" min="0" name="piece_rate[{$tmp_index}][]" value="{$vo2.piece_rate}">
                                        </div>
                                         {/if}
                                        <div class="btn-group pull-right" style="float: inherit!important;">
                                            <button class="btn btn-warning cancel_item">移除</button>
                                        </div>
                                    </div>
                                    {/foreach}

                                </div>
                            </div>
                            {php}$tmp_index++;{/php}
                            {/foreach}
                        </div>
                        <div class="btn-group" style="display: block; width: 170px; margin: 0 auto;">
                            <div type="submit" class="btn btn-info" id="add_thing">添加事件</div>
                            <div class="btn btn-info next" style="margin-left: 20px;">下一步</div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">主题:</label>
                            <div class="col-sm-4">
                                <input style="border-radius: 6px;" class="form-control" name="theme" value="{$list['theme']['theme']}" placeholder="主题">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注:</label>
                            <div class="col-sm-4">
                                <input style="border-radius: 6px;" class="form-control" name="desc" value="{$list['theme']['desc']}" placeholder="备注">
                            </div>
                        </div>
                        <div class="check">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">初审人:</label>
                                <div class="col-sm-2">
                                    <input name="first_check_user_name" style="border-radius: 6px;" class="form-control classname" value="{$buckle_user[$list['theme']['first_check_user_id']]['name']}" placeholder="初审人" autocomplete="off"/>
                                    <input type="hidden" name="first_check_user_id" value="{$list['theme']['first_check_user_id']}">
                                </div>

                                <label class="col-sm-1 control-label">终审人:</label>
                                <div class="col-sm-2">
                                    <input name="last_check_user_name" style="border-radius: 6px;" class="form-control classname" value="{$buckle_user[$list['theme']['last_check_user_id']]['name']??''}" placeholder="终审人" limits_b="" autocomplete="off"/>
                                    <input type="hidden" name="last_check_user_id" value="{$list['theme']['last_check_user_id']??''}">
                                </div>
                            </div>
                        </div>
                        <div class="check">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">奖扣时间:</label>
                                <div class="col-sm-2">
                                    <input type="text" name="prize_buckle_time" value="{$list['theme']['prize_buckle_time']}" style="border-radius: 6px;"
                                           class="form-control timepicker">
                                </div>
                                <label class="col-sm-1 control-label">抄送人:</label>
                                <div class="col-sm-2">
                                    <input name="copy_user_name" style="border-radius: 6px;" class="form-control classname" value="{$buckle_user[$list['theme']['copy_user_id']]['name']??''}" placeholder="抄送人" />
                                    <input type="hidden" name="copy_user_id" value="{$list['theme']['copy_user_id']??''}">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-2"></div>
                        <div class="col-sm-8">

                            <div class="btn-group pull-right">
                                <div class="btn btn-info pull-left last" style="margin-right: 20px;">上一步</div>
                                <button type="submit" id="audit_sub_submit"
                                        class="btn btn-info pull-right"
                                        data-loading-text="&lt;i class='fa fa-spinner fa-spin  '&gt;&lt;/i&gt; 提交">提交
                                </button>
                                <button class="submits" style="display: none"></button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>


</section>
<!-- 快捷设置人员分值 -->
<script>
    $(".tab-content").on("input propertychange",".fast_set input",function(){
        let value = $(this).val();
        let name = $(this).attr("data-name");
        let list = $(this).parents(".tab-pane").find(".user_list ."+name);
        if(list.length > 0){
            for (let i = 0; i < list.length; i++) {
                list.eq(i).val(value);
            }
        }
    })
</script>
<!-- 添加删除事件方法 -->
<script>
    var item = '<div class="tab-pane active">\n' +
        '            <div class="form-group">\n' +
        '                <label class="col-sm-2 control-label">事件编号:</label>\n' +
        '                <div class="col-sm-4 thing_num" style="line-height:33px;">\n' +
        '                    1\n' +
        '                </div>\n' +
        '                <input type="hidden" value="0" class="even_number" name="number[]">\n' +
        '            </div>\n' +
        '            <div class="form-group">\n' +
        '                <label class="col-sm-2 control-label">事件</label>\n' +
        '                <div class="col-sm-4">\n' +
        '                    <input type="text" name="" value="" is_piece="" style="border-radius: 6px;" class="form-control things_check" placeholder="事件选择" />\n' +
        '                    <input type="hidden" class="things_check_id" name="event_id[]" value="" >\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="form-group">\n' +
        '                <label class="col-sm-2 control-label">描述</label>\n' +
        '                <div class="col-sm-4">\n' +
        '                                        <textarea name="event_desc[]" class="form-control"\n' +
        '                                                  style="height: 100px;border-radius: 6px;"></textarea>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div style="text-align: right;width: 50%">\n' +
        '                <div class="btn-group add_user" style="margin-left: 20px;">\n' +
        '                    <div type="submit" class="btn btn-info pull-right add_take">添加参与人</div>\n' +
        '                </div>\n' +
        '                <div class="btn-group">\n' +
        '                    <button class="btn btn-info cancel_this">删除</button>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="user_list" style="margin-top: 10px;">\n' +
        '\n' +
        '            </div>\n' +
        '        </div>';
    $("#add_thing").click(function () {
        $(".tab-content").append(item);
        sort_num();
    });
    $(".tab-content").on("click",".cancel_this",function () {
        if ($(".tab-content .tab-pane").length > 1) {
            $(this).parents(".tab-pane").remove();
            sort_num();
        }else{
            layui.layer.msg("至少有一个事件");
        }
    });
    // 编号重写方法
    function sort_num(){
        var sort_item = $(".tab-content .tab-pane");
        console.log(sort_item.length);
        for (let i = 0; i < sort_item.length; i++) {
            sort_item.eq(i).find(".thing_num").html(i+1);
            sort_item.eq(i).find(".even_number").val(i);
            var cyr_id = sort_item.eq(i).find(".cyr_id");
            var integral_a = sort_item.eq(i).find(".integral_a");
            var integral_b = sort_item.eq(i).find(".integral_b");
            var piece_rate = sort_item.eq(i).find(".piece_rate");
            for (let a = 0; a < cyr_id.length; a++) {
                cyr_id.eq(a).attr("name","user_id["+i+"][]")
                integral_a.eq(a).attr("name","integral_a["+i+"][]")
                integral_b.eq(a).attr("name","integral_b["+i+"][]")
                piece_rate.eq(a).attr("name","piece_rate["+i+"][]")
            }
        }
    }
</script>
<!-- 点击下一步上一步判定 -->
<script>
    $('.next').click(function () {
        var things_check = $(".tab-content .things_check_id");
        for (let i = 0; i < things_check.length; i++) {
            // things_check.eq(i).val();
            if (things_check.eq(i).val()=="") {
                layui.layer.msg("事件不能为空");
                return false;
            }
        };
        // var user_list = $(".tab-content .user_list");
        // for (let i = 0; i < user_list.length; i++) {
        //     // user_list.eq(i).find(".user_item");
        //     if (user_list.eq(i).find(".user_item").length==0) {
        //         layui.layer.msg("参与人不能为空");
        //         return false;
        //     }
        // }
        var user_list = $(".tab-content .user_list");
        for (let i = 0; i < user_list.length; i++) {
            // user_list.eq(i).find(".user_item");
            if (user_list.eq(i).find(".user_item").length==0) {
                layui.layer.msg("参与人不能为空");
                return false;
            }else{
                for (let j = 0; j < user_list.eq(i).find(".user_item").length; j++) {
                    var a = user_list.eq(i).find(".user_item").eq(j).find(".integral_a").val();
                    var b = user_list.eq(i).find(".user_item").eq(j).find(".integral_b").val();
                    if (a == "" && b == "") {
                        layui.layer.msg("参与人分值不能为空");
                        return false;
                    }
                }
            }
        }
        $(".box-footer").show();
        $(".tab-content-wrap").hide();
        //判断是否为多事件添加主题和时间
        let now_time = new Date();
        let year = now_time.getFullYear();
        let month = now_time.getMonth()+1;
        let day = now_time.getDate();
        let title;
        if($(".tab-content .tab-pane").length > 1){
            title = year+'-'+month+'-'+day;
        }else{
            title = $(".tab-content .tab-pane .things_check").val();
            title = year+'-'+month+'-'+day + '-' + title;
        }
        $(".box-footer input[name='theme']").val(title);
        let timepicker = year+'-'+month+'-'+day;
        $(".box-footer .timepicker").val(timepicker);
    });
    $('.last').click(function () {
        $(".box-footer").hide();
        $(".tab-content-wrap").show();
    })
</script>


<!-- 颜学军代码开始 -->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">事件选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;"><span
                                        class="glyphicon glyphicon-search"></span></button>
                            </span>
                        </div>
                    </div>

                    <div class="input-group table-body">
                        <div class="table-left">
                            <div id="test13" class="demo-tree-more"></div>
                        </div>
                        <div class="table-right">
                            <h4>群艺积分（武汉）管理咨询有限公司</h4>
                            <p><span>宋剑/087/学员部门</span> <input type="checkbox"></p>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="confirm">确认</button>
            </div>
        </div>
    </div>

</div>
<script type="application/javascript">

    // let next = document.querySelector(".next");
    // let last = document.querySelector(".last");
    // let boxFooter = document.querySelector(".box-footer");
    // let tabContentWrap = document.querySelector(".tab-content-wrap");
    // next.onclick = function () {
    //     boxFooter.style.display = "block";
    //     tabContentWrap.style.display = "none";
    //     next.style.display = "none";
    // }
    // last.onclick = function () {
    //     boxFooter.style.display = "none";
    //     tabContentWrap.style.display = "block";
    //     next.style.display = "block";
    // }

    $(document).ready(function () {
        /*ajax页面加载icheck，有该控件的页面才需要*/
        $(".select2").select2({ language: "zh-CN" });

    })
    $('.minimal').on('click', function () {
        var type = $(this).val();
        if (type == 1) {
            $('.check').show();
        } else if (type == 0) {
            $('.check').hide();
        }

    });
    var number = 1;
    // add新事件
    $('#add').click(function () {
        number++;
        var users = '{:json_encode($event)}';
        users = JSON.parse(users);
        var data = '';
        $.each(users, function (key, val) {

            if (val.p_cate_name == null) {
                data += '<option value="' + val.id + '">' + val.name + '/' + val.cate_name + '</option>\n';
            }
            else {
                data += '<option value="' + val.id + '">' + val.name + '/' + val.cate_name + '/' + val.p_cate_name + '</option>\n';
            }
        });
        var str = '<div class="tab-content">\n' +
            '                            <div class="tab-pane active">\n' +
            '                                <div class="form-group">\n' +
            '                                    <label class="col-sm-2 control-label">事件编号:</label>\n' +
            '                                    <div class="col-sm-4" style="line-height:33px;">\n' +
            number +
            '                                    </div>\n' +
            '                                    <input type="hidden" value="' + number + '" class="even_number" name="number[]">\n' +
            '                                </div>\n' +
            '                                <div class="form-group">\n' +
            '                                    <label class="col-sm-2 control-label">事件</label>\n' +
            '                                    <div class="col-sm-4">\n' +
            '                                             <input type="text" style="border-radius: 6px;" class="form-control classname" placeholder="事件选择"/>\n' +
            '                                    </div>\n' +
            '                                </div>\n' +
            '                                <div class="form-group">\n' +
            '                                    <label class="col-sm-2 control-label">描述</label>\n' +
            '                                    <div class="col-sm-4">\n' +
            '                                        <textarea name="event_desc[]" class="form-control" style="height: 100px;"></textarea>\n' +
            '                                    </div>\n' +
            '                                </div>\n' +
            '                                <div class="user_list">\n' +
            '\n' +
            '                                </div>\n' +
            '                            </div>\n' +
            '                            <div class="col-sm-2"></div>\n' +
            '                            <div class="col-sm-4">\n' +
            '                                <div class="btn-group pull-right add_user" style="margin-left: 20px;">\n' +
            '                                    <div type="submit" class="btn btn-info pull-right">添加参与人</div>\n' +
            '                                </div>\n' +
            '                                <div class="btn-group pull-right">\n' +
            '                                    <button class="btn btn-info cancel_fq">删除</button>\n' +
            '                                </div>\n' +
            '                            </div>\n' +
            '                            <div class="clear"></div>\n' +
            '                        </div>'
        $('.tab-content-wrap').append(str)
    })
    $(document).on('focus', '.classname', function () {
        // $('#myModal').modal('show');
    })
    // 删除事件
    $(document).on('click', '.cancel_fq', function () {
        $(this).parents('.tab-content').remove();
    })
    // add参与人
    $(document).on('click', '.add_user', function () {
        // $('#myModal').modal('show');
        let that = this;
        let confirm = document.getElementById("confirm");
        confirm.onclick = function () {
            $('#myModal').modal('hide');
            for (let i = 0; i < 2; i++) {
                add_user();
            }
        }
        function add_user() {
            var users = '{:json_encode($users)}';
            users = JSON.parse(users);
            var data = '';
            $.each(users, function (key, val) {
                data += '<option value="' + val.id + '">' + val.name + '/' + val.department_name + '</option>\n';
            });
            var value = $(that).parents('.tab-content').find('.even_number').val();
            console.log(value);
            var str = '<div class="form-group user_item">\n' +
                ' <label class="col-sm-2 control-label">参与人</label>\n' +
                ' <div class="col-sm-1">\n' +
                ' <input type="text" style="border-radius: 6px;" class="form-control" placeholder="参与人" />\n' +
                ' </div>\n' +
                ' <label class="col-sm-1 control-label">A分</label>\n' +
                ' <div class="col-sm-1">\n' +
                ' <input class="form-control" type="number" min="0" name="integral_a[' + value + '][]">\n' +
                ' </div>\n' +
                ' <label class="col-sm-1 control-label">B分</label>\n' +
                ' <div class="col-sm-1">\n' +
                ' <input class="form-control" type="number" min="0" name="integral_b[' + value + '][]">\n' +
                ' </div>\n' +
                ' <label class="col-sm-1 control-label">计件</label>\n' +
                ' <div class="col-sm-1">\n' +
                ' <input class="form-control" type="number" min="0" name="piece_rate[' + value + '][]">\n' +
                ' </div>\n' +
                ' <div class="btn-group pull-right" style="float: inherit!important;">\n' +
                ' <button class="btn btn-warning cancel_item">移除</button>\n' +
                ' </div>\n' +
                ' </div>';
            $(that).parents('.tab-content').find('.user_list').append(str)
        }
    })
    // 删除参与人
    $(document).on('click', '.cancel_item', function () {
        $(this).parents('.user_item').remove()
    })
</script>
<!-- 颜学军代码结束 -->


<!-- 弹框样式引入 -->
<link rel="stylesheet" href="__STATIC__/global/an_tree_css/an_tree_css.css">
<script>
    // 时间选择器
    layui.use(['tree', 'laydate'], function () {
        var tree = layui.tree;
        var laydate = layui.laydate;
        var nowtime = "{:date('Y-01-01 H:i:s',time())}";
        console.log(nowtime);
        var end_time  = laydate.render({
            elem: '.timepicker'
            ,min: nowtime //0天前
            , max: 7 //7天后
            ,type: 'datetime'//样式
        });
        var apply_end_time  = laydate.render({
            elem: '.apply_end_time'
            , min: nowtime //0天前
            , max: 7 //7天后
            , type: 'datetime' //样式
        });
    });
</script>


<!-- Modal 弹出层重写 事件选择  -->
<div class="modal fade" id="myModal_things" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel_things">事件选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <!-- <div class="an_list_title">

                                </div> -->
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                        <div class="item_info">
                                            <span class="name">专审事件锁定测试</span>
                                            <span>工作类事件 / 日常工作类事件</span>
                                        </div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit">确认</button>
            </div>
        </div>
    </div>
    <!-- <div class="content_tips">
        <p>事件分类：<span>工作类事件/ 日常工作类事件</span></p>
        <p>分值范围：<span>A分:0 ~ 0 B分:100 ~ 200 产值:0 ~ 0</span></p>
        <p>事件属性：<span>专审事件 计件事件</span></p>
        <p><p>备注信息：</p><p><span>暂无备注信息</span></p></p>
    </div> -->
</div>
<!-- 提示操作 事件选择  -->
<script>
    $("#myModal_things").on("mouseenter",".an_list_item", function () {
        var i = $("#myModal_things .an_list_con .an_list_item").index(this);
        $("#myModal_things .content_tips").eq(i).show();
    });
    $("#myModal_things").on("mouseleave",".an_list_item", function () {
        $("#myModal_things .content_tips").hide();
    });
    $('#myModal_things').mousemove(function (e) {
        var xx = e.originalEvent.x;//e.originalEvent.x; || e.originalEvent.layerX || 0
        var yy = e.originalEvent.y;//e.originalEvent.y; || e.originalEvent.layerY || 0;
        $("#myModal_things .content_tips").css("left", xx);
        $("#myModal_things .content_tips").css("top", yy);
        // console.log(xx);
        // console.log(yy);
    });
</script>
<!-- 单选弹窗操作 事件选择  -->
<script>
    var now_item_name;//名字输入框
    var now_item_id;//id输入框
    var now_item_fast_set;//快捷设置计件节点
    var now_item_things_tips;//事件提示节点
    //确认按钮
    $('#myModal_things .popups_submit').click(function (e) {
        $('#myModal_things').modal('hide');
        var checked = $(".an_tree_list").find(".list_item_check");
        now_item_name.val(checked.attr("data_name"));
        now_item_id.val(checked.attr("data_id"));
        now_item_name.attr("is_piece",checked.attr("is_piece"));
        //获取提示信息
        var i = $("#myModal_things .an_list_con .an_list_item").index(checked);//选中第几个元素
        var check_tips = $("#myModal_things .content_tips").eq(i).prop("outerHTML");//选中所选元素的提示信息
        now_item_things_tips.html(check_tips);
        now_item_things_tips.find(".content_tips").css("left", 0).css("top", 0).show();
        //判断是否为计件事件，快捷设置里面添加计件
        if(checked.attr("is_piece") == 0){
            now_item_fast_set.hide();
        }else{
            now_item_fast_set.show();
        };
        //事件分值赋值
        now_item_id.attr("integral_a_start", checked.attr("integral_a_start"));
        now_item_id.attr("integral_a_end", checked.attr("integral_a_end"));
        now_item_id.attr("integral_b_start", checked.attr("integral_b_start"));
        now_item_id.attr("integral_b_end", checked.attr("integral_b_end"));
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_things').on('hidden.bs.modal', function () {
        // 执行一些动作...重置弹窗
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_things input[name='search_user_name']").val("");
    });
    // 事件选择
    $('.tab-content').on('focus','.things_check', function () {
        $('#myModal_things').modal('show');
        now_item_name = $(this);
        now_item_id = $(this).siblings(".things_check_id");//节点
        //快捷设置计件节点
        now_item_fast_set = $(this).parents(".tab-pane").find(".fast_set_isPiece");
        now_item_things_tips = $(this).parents(".tab-pane").find(".things-tips");
    });
</script>
<!-- 树结构js操作 事件选择  -->
<script>
    $("#myModal_things .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_things").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        // var department_name = $(this).html();
        var user_name = $("#myModal_things input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_event_child')}",
            data: {'id' : department_id,'search_name' : user_name},
            dataType:"json",
            success: function (data) {
                // // var json = JSON.parse(data);
                // console.log(data);
                // // return false;
                var content = '';
                var content_tips = '';
                $.each(data, function (index, value) {
                    if (value.is_piece) {
                        var is_piece = '<p>事件属性：<span>计件事件</span></p>';
                    } else {
                        var is_piece = '';
                    }
                    if (value.desc == "") {
                        var desc = '<span>暂无备注信息</span>'
                    } else {
                        var desc = '<span>'+value.desc+'</span>'
                    }
                    content += '<div class="an_list_item" data_id="'+value.id+'" data_name="'+value.name+'" is_piece="'+value.is_piece+'"> <div class="item_box item_box_check"><i class="fa fa-check"></i></div> <div class="item_info"> <span class="name">'+value.name+'</span> <span>'+value.show_cate_name+'</span> </div> </div>';
                    content_tips += '<div class="content_tips"> <p>事件分类：<span>'+value.show_cate_name+'</span></p> <p>分值范围：<span>A分:'+value.integral_a_start+' ~ '+value.integral_a_end+' B分:'+value.integral_b_start+' ~ '+value.integral_b_end+'</span></p>'+is_piece+'<p><p>备注信息：</p><p>'+desc+'</p></p> </div>'
                });
                $('.an_list_con').html("");
                $('.an_list_con').append(content);
                $("#myModal_things .content_tips").remove();
                $("#myModal_things").append(content_tips);
            }
        })
    });
    $("#myModal_things .an_tree_list").on("click", ".an_list_item", function () {
        $(this).siblings().removeClass("list_item_check");
        $(this).toggleClass("list_item_check")
    })
</script>
<!-- 递归填充目录 事件选择  -->
<script>
    var an_tree = ergodic({$eventList});
    $("#myModal_things .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        // console.log(data);
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.name + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.name + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>



<!-- Modal 弹出层重写 单选  -->
<div class="modal fade" id="myModal_single" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModal_single">人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit">确认</button>
            </div>
        </div>
    </div>

</div>
<!-- 单选弹窗操作  -->
<script>
    var double_max;//扣分上限
    var first_id="";//初审人id
    var last_id="";//终审人id
    var now_item_name;//名字输入框
    var now_item_id;//id输入框
    var user_type;
    //确认按钮
    $('#myModal_single .popups_submit').click(function (e) {
        $('#myModal_single').modal('hide');
        var checked = $(".an_tree_list").find(".list_item_check");
        now_item_name.val(checked.attr("user_name"));
        now_item_id.val(checked.attr("user_id"));
        now_item_name.attr("limits_b",checked.attr("limits_b"))
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_single').on('hidden.bs.modal', function () {
        // 执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_single input[name='search_user_name']").val("");
    });
    // 任务负责人
    $("input[name='copy_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        double_max = 0;
        now_item_name = $(this);
        now_item_id = $("input[name='copy_user_id']");//节点
        user_type = 0;
    });
    // 初审人
    $("input[name='first_check_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        double_max = $("input[name='double_max']").val();
        now_item_name = $(this);//节点
        now_item_id = $("input[name='first_check_user_id']");//节点
        last_id = $("input[name='last_check_user_id']").val();//id值
        user_type = 1;
    });
    // 终审人
    $("input[name='last_check_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        double_max = $("input[name='double_max']").val();
        now_item_name = $(this);//节点
        now_item_id = $("input[name='last_check_user_id']");//节点
        first_id = $("input[name='first_check_user_id']").val();//id值
        user_type = 2;
    });
</script>
<!-- 树结构js操作 单选  -->
<script>
    $("#myModal_single .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_single").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_single input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {'department_id' : department_id,'score' : double_max,'first_check_user_id' : first_id,'last_check_user_id' : last_id,'user_type' : user_type ,'user_name' : user_name},
            dataType:"json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if(value.limits==undefined){
                        var limits=0;
                    }else{
                        var limits=value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="'+value.name+'" user_id="'+value.id+'" limits_b="'+limits+'"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('.an_list_con').html("");
                $('.an_list_con').append(content);
                $('.an_list_title').html(department_name + data.length + '人');
            }
        })
    });
    $("#myModal_single .an_tree_list").on("click", ".an_list_item", function () {
        $(this).siblings().removeClass("list_item_check");
        $(this).toggleClass("list_item_check")
    })
</script>
<!-- 递归填充目录 单选  -->
<script>
    var an_tree = ergodic({$department});
    $("#myModal_single .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>



<!-- Modal 弹出层重写 多选   -->
<div class="modal fade" id="myModal_multiple" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel10">人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input type="text" name="search_user_name" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;"><span
                                        class="glyphicon glyphicon-search"></span></button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-right">
                    <div class="multiresult_header">
                        <div>已选择<span class="number">0</span>个</div>
                        <div class="header_clear">清空</div>
                    </div>
                    <div class="multiresult_list">
                        <!-- <div class="an_list_item">
                            <div class="item_info">
                                <span class="name">aaa</span>/
                                <span>88</span>/
                                <span>部门</span>
                            </div>
                            <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                        </div> -->

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit" id="submit2">确认</button>
            </div>
        </div>
    </div>
</div>
<!-- 多选弹窗操作  -->
<script>
    var now_item_multiple="";//名字输入框
    var input_name="";
    var is_piece="";
    $(".tab-content").on("click",".add_take",function () { 
        is_piece = $(this).parents(".tab-pane").find(".things_check").attr("is_piece");
        if (is_piece == "") {
            layui.layer.msg("请先选择事件");
        } else {
            $('#myModal_multiple').modal('show');
            now_item_multiple=$(this).parents(".tab-pane").find(".user_list");
            input_num = $(this).parents(".tab-pane").find(".even_number").val();
            new_right_add();
            pcqt_people=[];
            last_id = $("input[name='last_check_user_id']").val();
            csr_id = $("input[name='copy_user_id']").val();
            pcqt_people.push(last_id);//添加终审人
            pcqt_people.push(csr_id);//添加抄送人
        }
    });
    //确认按钮
    $('#myModal_multiple .popups_submit').click(function (e) {
        $('#myModal_multiple').modal('hide');
        var check_all = $("#myModal_multiple .multiresult_list .an_list_item");
        var item_ids = [];
        for (let i = 0; i < check_all.length; i++) {
            item_ids.push(check_all.eq(i).attr("user_id"));
        }
        var now_item = now_item_multiple.find(".user_item");
        for (let i = 0; i < now_item.length; i++) {
            var cyr_id = now_item.eq(i).find(".cyr_id").val();
            if ( $.inArray(cyr_id,item_ids) < 0) {
                now_item.eq(i).remove();
            }
        }
        var now_item_ids = [];
        for (let i = 0; i < now_item_multiple.find(".user_item").length; i++) {
            now_item_ids.push(now_item_multiple.find(".user_item").eq(i).find(".cyr_id").val());
        }
        var content="";
        if (is_piece == 1) {
            for (let i = 0; i < check_all.length; i++) {
                var input_value = check_all.eq(i).attr("user_id");
                var input_limits_b = check_all.eq(i).attr("limits_b");
                var input_user_name = check_all.eq(i).attr("user_name");
                var input_user_num = check_all.eq(i).find(".item_info span").eq(1).html();
                var input_apart_name = check_all.eq(i).find(".item_info span").eq(2).html();
                if ( $.inArray(input_value,now_item_ids) < 0) {
                    content += '<div class="form-group user_item"> <label class="col-sm-2 control-label">参与人</label> <div class="col-sm-1"><input type="text" name="" value="'+input_user_name+'" disabled style="border-radius: 6px;" value="" class="form-control cyr_name"> <input type="hidden" class="cyr_id" name="user_id['+input_num+'][]" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'"></div> <label class="col-sm-1 control-label">A分</label> <div class="col-sm-1"> <input class="form-control integral_a" type="number" name="integral_a['+input_num+'][]"> </div>  <label class="col-sm-1 control-label">B分</label> <div class="col-sm-1"> <input class="form-control integral_b" type="number" name="integral_b['+input_num+'][]"> </div> <label class="col-sm-1 control-label">计件</label> <div class="col-sm-1"> <input class="form-control piece_rate" type="number" min="1" value="1" name="piece_rate['+input_num+'][]"> </div> <div class="btn-group pull-right" style="float: inherit!important;"> <button class="btn btn-warning cancel_item">移除</button> </div> </div>';
                }
                // content += '<input type="hidden" name="'+input_name+'" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'">';
            }
        } else {
            for (let i = 0; i < check_all.length; i++) {
                var input_value = check_all.eq(i).attr("user_id");
                var input_limits_b = check_all.eq(i).attr("limits_b");
                var input_user_name = check_all.eq(i).attr("user_name");
                var input_user_num = check_all.eq(i).find(".item_info span").eq(1).html();
                var input_apart_name = check_all.eq(i).find(".item_info span").eq(2).html();
                // content += '<input type="hidden" name="'+input_name+'" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'">';
                if ( $.inArray(input_value,now_item_ids) < 0) {
                    content += '<div class="form-group user_item"> <label class="col-sm-2 control-label">参与人</label> <div class="col-sm-1"><input type="text" name="" value="'+input_user_name+'" disabled style="border-radius: 6px;" value="" class="form-control cyr_name"> <input type="hidden" class="cyr_id" name="user_id['+input_num+'][]" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'"></div> <label class="col-sm-1 control-label">A分</label> <div class="col-sm-1"> <input class="form-control integral_a" type="number" name="integral_a['+input_num+'][]"> </div>  <label class="col-sm-1 control-label">B分</label> <div class="col-sm-1"> <input class="form-control integral_b" type="number" name="integral_b['+input_num+'][]"> </div> <div class="btn-group pull-right" style="float: inherit!important;"> <button class="btn btn-warning cancel_item">移除</button> </div> </div>';
                }
            }
        }
        now_item_multiple.append(content);
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_multiple').on('hidden.bs.modal', function () {
        //执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_multiple input[name='search_user_name']").val("");
        $("#myModal_multiple .header_clear").click();
    });
    //已选择，再进行补充选择时添加右侧选中
    function new_right_add(){
        var input = now_item_multiple.find(".user_item .cyr_id");
        var content = ""
        for (let i = 0; i < input.length; i++) {
            input.eq(i).attr("");
            content += '<div class="an_list_item " user_name="'+input.eq(i).attr("user_name")+'" user_id="'+input.eq(i).attr("value")+'" limits_b="'+input.eq(i).attr("limits_b")+'"><div class="item_info"><span class="name">'+input.eq(i).attr("user_name")+'</span>/<span>'+input.eq(i).attr("input_user_num")+'</span>/<span>'+input.eq(i).attr("apart_name")+'</span></div><div class="item_box "><i class="fa fa-remove"></i></div></div>'
        }
        $("#myModal_multiple .multiresult_list").append(content);
    }
</script>
<!-- 树结构js操作 多选  -->
<script>
    $("#myModal_multiple .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    //添加中间人员列表
    $("#myModal_multiple").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_multiple input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {'department_id' : department_id,'user_name' : user_name,'user_type': 0,'last_check_user_id': pcqt_people,},
            dataType:"json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if(value.limits==undefined){
                         var limits=0;
                    }else{
                        var limits=value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="'+value.name+'" user_id="'+value.id+'" limits_b="'+limits+'"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('#myModal_multiple .an_list_con').html("");
                $('#myModal_multiple .an_list_con').append(content);
                $('#myModal_multiple .an_list_title').html('<div>'+department_name + data.length + '人</div><div class="all_item_box"><i class="fa fa-check"></i></div>');
                left_add_active();
                check_all();
            }
        })
    });
    // 选中事件
    $("#myModal_multiple .an_tree_list").on("click", ".an_list_item", function () {
        $(this).toggleClass("list_item_check");
        var ischeck = $(this).attr("class");
        if (ischeck.indexOf("list_item_check") >= 0) {
            add_check();
        } else {
            del_check($(this).attr("user_id"));
        }
        check_all();
    });
    //全选按钮
    $("#myModal_multiple .an_tree_list").on("click", ".all_item_box", function () {
        $(this).toggleClass("all_item_box_check");
        var ischeck = $(this).attr("class");
        var all_item = $("#myModal_multiple .an_tree_list .an_list_item");
        if (ischeck.indexOf("all_item_box_check") >= 0) {
            all_item.addClass("list_item_check");
            add_check();
        } else {
            all_item.removeClass("list_item_check")
            for (let i = 0; i < all_item.length; i++) {
                del_check(all_item.eq(i).attr("user_id"));
            }
        }
        check_all();
    });
    //右侧删除事件
    $("#myModal_multiple .multiresult_list").on("click", ".item_box", function () {
        var user_id = $(this).parents(".an_list_item ").attr("user_id");
        del_check(user_id);
        check_all();
    });
    //右侧清空监听
    $("#myModal_multiple .multiresult_header").on("click", ".header_clear", function () {
        var all_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < all_item.length; i++) {
            del_check(all_item.eq(i).attr("user_id"));
        }
        check_all();
    });
    //全选按钮检测
    function check_all(){
        var all_item_num = $("#myModal_multiple .an_tree_list .an_list_item").length;
        var checked_item_num = $("#myModal_multiple .an_tree_list .list_item_check").length;
        if(all_item_num != 0 && all_item_num == checked_item_num){
            $("#myModal_multiple .an_tree_list .all_item_box").addClass("all_item_box_check");
        }else{
            $("#myModal_multiple .an_tree_list .all_item_box").removeClass("all_item_box_check");
        };
        //右侧选中人数统计
        var people_num = $("#myModal_multiple .multiresult_list .an_list_item").length;
        $("#myModal_multiple .multiresult_header .number").html(people_num);
    };
    //添加右侧选中项
    function add_check(){
        var item_ids = [];
        var all_checked_item = $("#myModal_multiple .an_list_con").find(".list_item_check");
        var now_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < now_checker_item.length; i++) {
            item_ids.push(now_checker_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < all_checked_item.length; i++) {
            var now_id = all_checked_item.eq(i).attr("user_id");
            if ( $.inArray(now_id,item_ids) < 0 ) {
                var new_item = all_checked_item.eq(i).prop("outerHTML");
                new_item = new_item.replace("fa-check","fa-remove");
                new_item = new_item.replace("list_item_check","");
                $("#myModal_multiple .multiresult_list").append(new_item);
            } 
        }
        // console.log(item_ids);
    }
    //左侧第一次生成时检测是否有选中项
    function left_add_active(){
        var left_item_ids = [];
        var left_checked_item = $("#myModal_multiple .an_list_con .an_list_item");
        var right_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < left_checked_item.length; i++) {
            left_item_ids.push(left_checked_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < right_checker_item.length; i++) {
            var user_id = right_checker_item.eq(i).attr("user_id");
            if ( $.inArray(user_id,left_item_ids) >= 0 ) {
                $("#myModal_multiple .an_list_con .an_list_item[user_id="+user_id+"]").addClass("list_item_check");
            }
        }  
    }
    //取消选中项
    function del_check(user_id){
        var left_item_ids = [];
        var right_item_ids = [];
        var left_checked_item = $("#myModal_multiple .an_list_con .an_list_item");
        var right_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < left_checked_item.length; i++) {
            left_item_ids.push(left_checked_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < right_checker_item.length; i++) {
            right_item_ids.push(right_checker_item.eq(i).attr("user_id"));
        }
        if ( $.inArray(user_id,left_item_ids) >= 0 ) {
           $("#myModal_multiple .an_list_con .an_list_item[user_id="+user_id+"]").removeClass("list_item_check");
        }
        if ( $.inArray(user_id,right_item_ids) >= 0 ) {
            $("#myModal_multiple .multiresult_list .an_list_item[user_id="+user_id+"]").remove();
        }
    }
</script>
<!-- 递归填充目录 多选  -->
<script>
    var an_tree = ergodic({$department});
    $("#myModal_multiple .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>



<!-- 拟稿提交按钮触发弹窗_ -->
<script>
    $("#audit_sub_submit").click(function () {
        var check_id = $("input[name='first_check_user_id']").val();
        var now_id = $(this).attr("data");
        if ( check_id == now_id ) {
            $('#myModal2').modal('show');
            $("#tips_submit").click(function (e) {
                var check_opinion = $("#check_opinion_textarea").val();
                $("#check_opinion").val(check_opinion);
                $('#myModal2').modal('hide');
                $(".submits").click();
            });
        }else{
            $(".submits").click();
        }
        return false;
    });
</script>
<!-- 拟稿提交按钮触发弹窗DOM结构_ -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        <div class="modal-content move" style="height: 282px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">提示</h4>
            </div>
            <div class="modal_body" style="width: 100%;padding: 20px;">
                <label style="width: 100%;margin: 0!important;">
                    请填写您的初审意见：
                    <textarea name="check_opinion_textarea" id="check_opinion_textarea" cols="45" rows="5"
                              style="display: block;width: 100%;max-height: 100px; margin:0;padding: 10px;border-radius: 5px;"
                              placeholder="可以输入一千字"></textarea>
                </label>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="tips_submit">确认</button>
            </div>
        </div>
    </div>
</div>
{/block}